<?php
include "../../lib/list.php";
if($_GET['table']){
	$table = clean($_GET['table']);
}
if($_GET['i']){
	$i = $_GET['i'];
}
if($_POST['table']){
	$table = clean($_POST['table']);
}
if($_POST['i']){
	$i = $_POST['i'];
}
if($_POST['barcode']){
	$barcode = clean($_POST['barcode']);
	$sear_barcode = " and barcode = '$barcode' or rot_barcode = '$barcode'";
}

$qry  = "select * from $table where 1 $sear_barcode";
$list = DBarray($qry);

if(empty($barcode)){
	$chk_result = '바코드를 입력해 주세요.';
}
else if(strlen($barcode)>13||strlen($barcode)<8){
	$chk_result = '잘못된 바코드입니다.';	
}
else if(barcode_check(substr($barcode,0,12))!=$barcode){
	$chk_result = 'Err. Check digit :: '.$barcode;
}
else{
	if(!$list){
		$chk_result = '<font color=blue>사용가능합니다.</font>';
		$chk = 1;
	}else{
		$chk_result = '<font color=red>이미 다른 상품 바코드가 존재합니다.</font>';
	}
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<link rel="stylesheet" href="../../css/insert.css" type="text/css"></link>
<link rel="stylesheet" href="../../css/list.css" type="text/css"></link>
<script>
function number_check(f){
    var num = "0123456789";
    var check = 0;
    var str = f.value;
    var len = f.value.length;
    for(var i=0; i<len; i++)   if(num.indexOf(str.substring(i,i+1)) >= 0)  check++;
    if(check != len){
           alert('숫자만 입력이 가능합니다');
           f.value='';
               return false;
        }
}
function insert(){
	var barcode = document.chk_barcode.new_barcode.value;
	var i = document.chk_barcode.i.value;
	opener.insert_rot_barcode(barcode,i);
	window.close();
}
</script>
</head>
<body>
	<div style="width: 320px; padding: 10px;">
		<div
			style="border-bottom: 1px solid #e8e8e8; text-align: left; font-size: 12px; margin-bottom: 12px; color: #9a9a9a">:::
			중복 검사</div>
		<form name="chk_barcode" method="post" action="chk_rot_barcode.php">
			<input type="hidden" name="table" value="<?=$table?>"></input>
			<input type="hidden" name="i" value="<?=$i?>"></input>
			<input type="hidden" name="new_barcode" value="<?=$barcode?>"></input>
			<div id=register>
				<ul class='line'></ul>
				<ul>
					<li class='value' style="margin-left: 7px;width:350px;"><input type='text'
						size='20' name='barcode' value='<?=$barcode?>' onkeyup="number_check(this);"/> <input type='submit'
						class='button green small' value='중복확인' style="width: 70px;" />
						</li>
				</ul>
				<ul style="padding-top: 8px; margin: 0px; text-align: center;">
					<li><?=$chk_result?></li>
				</ul>
				<ul class='line'></ul>
			</div>
		</form>
		<div style="padding: 5px;">
			<center>
			<?if($chk == 1)echo "<input
				type='button' class='button blue small' value='입력하기' onclick='javacsript:insert()'/>";?>
				<input type="button" class="button white small" value="취소하기"
					onclick="javacsript:window.close()" />
			</center>
		</div>
	</div>
</body>
</html>
